﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tester.DL645.Core;

namespace Tester.DL645.Instructions
{
    /// <summary>
    /// 拉闸指令
    /// </summary>
    public class OffInstruction : AbstractInstruction
    {
        public string Password { get; set; }
        public string Auth { get; set; }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="address"></param>
        public OffInstruction(string address, string password = "0000", string auth = "02")
            : base(address, 0X1C)
        {
            this.Password = password;
            this.Auth = auth;
        } 
        /// <summary>
        /// 
        /// </summary>
        private  void ApplyPassword(List<byte> buffer)
        {
           // buffer.AddRange(PasswordField.Reverse(this.Password));

            buffer.AddRange(new byte[] { 0x33 ,0x33 ,0x33 });
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="buffer"></param>
        /// <param name="password"></param>
        private  void ApplyAuth(List<byte> buffer)
        {
            //var authByte = (byte)(byte.Parse(this.Auth, System.Globalization.NumberStyles.HexNumber) + 0X33);
            buffer.Add(0x35);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="buffer"></param>
        private  void ApplyOperator(List<byte> buffer)
        {
            buffer.AddRange(Constants.OperatorCharacters);
        }
        /// <summary>
        /// 应用数据
        /// </summary>
        /// <param name="buffer"></param>
        protected override void ApplyData(List<byte> buffer)
        {
            var ii = 0;
            buffer.Add(0X10);
            //4
            this.ApplyAuth(buffer);
            this.ApplyPassword(buffer);
            //4
            this.ApplyOperator(buffer);
          
            buffer.AddRange(new byte[] {
                    0X4D,
                    0X33,
                    0X8C,0X8C,0X56,0X48,0X3B,0X58});




        }
        

    }
}
